package com.william.jdbcplus.core.dialect.pagination.impl;

import com.william.jdbcplus.core.dialect.pagination.IPagination;

/**
 * DB2 数据库分页方言
 *
 * @author niliwei
 */
public class DB2Pagination implements IPagination {

    @Override
    public String getPaginationSql(String originalSql, long offset, long limit) {
        long firstParam = offset + 1;
        long secondParam = offset + limit;
        String sql = "SELECT * FROM (SELECT TMP_PAGE.*,ROWNUMBER() OVER() AS ROW_ID FROM ( " + originalSql
                + " ) AS TMP_PAGE) TMP_PAGE WHERE ROW_ID BETWEEN " + firstParam + " AND " + secondParam;
        return sql;
    }
}
